package com.utils {
	import flash.display.*;
	import flash.utils.*;
	import flash.events.*;
	import flash.text.*;

	public class TextAnimation extends Sprite {

		private var _textInfo:String;
		private var _fieldMap:Bitmap;
		private var _bmpData:BitmapData;
		private var _speed:Number = -2;
		private var _alphaNum:Number = 0.05;
		private var _startAlphaNum:int = 30;
		private var _startPlay:int = 0;
		private var _stopPlay:int = 0;
		private var _target:DisplayObject;
		private var _txtX:Number = 0;
		private var _txtY:Number = 0;
		private var _onAnimationEnd:Function;
		private var _textField:TextField;
		private var _textFromet:TextFormat;
		private var _timer:Timer;
		private var _timerNum:int = 0;
		private var _numY:int = 0;

		public function TextAnimation() {
			this._onAnimationEnd = new Function();
			this._timer = new Timer(10);
			super();
			this._textField = new TextField();
			this._textField.autoSize = TextFieldAutoSize.LEFT;
			this._textField.mouseEnabled = false;
			this._textField.mouseWheelEnabled = false;
			this._textField.selectable = false;
			this._textField.filters = [Filter.filter2];
			this._textFromet = new TextFormat();
			this._textFromet.size = 12;
			this._timer.addEventListener(TimerEvent.TIMER, this.onTimerEvent);
			this._textField.alpha = 0;
		}

		public function set textInfo(_arg1:String):void {
			this._textField.htmlText = _arg1;
			this._textField.setTextFormat(this._textFromet);
			this.drawFile();
		}

		private function drawFile():void {
			this._bmpData = new BitmapData(this._textField.width, this._textField.height, true, 0);
			this._bmpData.draw(this._textField);
			this._fieldMap = new Bitmap(this._bmpData);
		}

		public function set color(_arg1:uint):void {
			this._textFromet.color = _arg1;
		}

		public function set bold(_arg1:Boolean):void {
			this._textFromet.bold = _arg1;
		}

		public function set size(_arg1:int):void {
			this._textFromet.size = _arg1;
		}

		public function set speed(_arg1:Number):void {
			this._speed = _arg1;
		}

		public function set alphaNum(_arg1:Number):void {
			this._alphaNum = _arg1;
		}

		public function set startAlphaNum(_arg1:int):void {
			this._startAlphaNum = _arg1;
		}

		public function set starPlay(_arg1:int):void {
			this._startPlay = _arg1;
		}

		public function set stopPlay(_arg1:int):void {
			this._stopPlay = _arg1;
		}

		public function set target(_arg1:DisplayObject):void {
			this._target = _arg1;
			if (this._target.parent) {
				this._target.parent.addChild(this._fieldMap);
				this._fieldMap.alpha = 0;
			}
			;
			if (this._txtX == 0) {
				return;
			}
			;
			this._fieldMap.y = ((this._fieldMap.y + this._numY) + this._txtY);
			this.textLive();
		}

		public function upChildIndex():void {
			if (this._target.parent) {
				this._target.parent.setChildIndex(this._fieldMap, (this._target.parent.numChildren - 1));
			}
			;
		}

		public function point(_arg1:Number, _arg2:Number):void {
			this._txtX = _arg1;
			this._txtY = _arg2;
			if (this._target == null) {
				return;
			}
			;
			this._fieldMap.y = ((this._fieldMap.y + this._numY) + this._txtY);
			this.textLive();
		}

		public function start():void {
			if ((((this._target == null)) || ((this._textField.length <= 0)))) {
				this._onAnimationEnd("");
				this._timer.stop();
				return;
			}
			;
			this._timer.start();
		}

		private function clear():void {
			this._bmpData.dispose();
			this._bmpData = null;
			if (((!((this._fieldMap == null))) && (this._fieldMap.parent))) {
				this._fieldMap.parent.removeChild(this._fieldMap);
				this._fieldMap = null;
			}
			;
			this._textField = null;
			this._timer.stop();
			this._timer.removeEventListener(TimerEvent.TIMER, this.onTimerEvent);
			this._timer = null;
		}

		public function set onAnimationEnd(_arg1:Function):void {
			this._onAnimationEnd = _arg1;
		}

		private function onTimerEvent(_arg1:TimerEvent):void {
			if (this._startPlay > 0) {
				this._startPlay--;
				return;
			}
			;
			if (this._stopPlay > 0) {
				this._stopPlay--;
			} else {
				this.textLive();
			}
			;
			if (this._timerNum == 0) {
				this._fieldMap.y = ((this._target.y + this._numY) + this._txtY);
				this.textLive();
			}
			;
			this._timerNum++;
			if (this._timerNum >= this._startAlphaNum) {
				if (this._fieldMap.alpha <= 0) {
					this.clear();
					this._onAnimationEnd("");
				} else {
					this._fieldMap.alpha = (this._fieldMap.alpha - this._alphaNum);
				}
				;
			} else {
				this._fieldMap.alpha = (this._fieldMap.alpha + this._alphaNum);
			}
			;
		}

		public function set numY(_arg1:int):void {
			this._numY = _arg1;
		}

		private function textLive():void {
			this._fieldMap.y = (this._fieldMap.y + this._speed);
			this._fieldMap.x = ((this._target.x - (this._fieldMap.width / 2)) + this._txtX);
			if (((this._fieldMap.parent) && (this._fieldMap))) {
				this._fieldMap.parent.setChildIndex(this._fieldMap, (this._fieldMap.parent.numChildren - 1));
			}
			;
		}

	}
}
